import time
from flask import request, abort
from utils import initApp
from src import common, config
from functools import wraps

from utils.initApp import app, default_response, mysql


@app.before_request
def check_option():
    print(request.method)
    if request.method == "OPTIONS":
        return default_response.construct_response("")


# @app.before_request
# def check_token():
#     _path = request.path
#     _ignore = False
#     print("请求路径", _path)
#     _ignore_path_list = [
#         "/login",
#         "/register"
#     ]
#     for cur in _ignore_path_list:
#         _ignore = _ignore or cur == _path
#     print("是否忽略token检查", _ignore)
#     if 'Token' not in request.headers and not _ignore:
#         abort(401)
#     if not _ignore:
#         _token = request.headers['Token']
#         _value = mysql.get('token', request.headers, "token")
#         print(_value)
#         if not _value:
#             abort(401)
#         _time = _token.split('-')[1]
#         _time = common.make_base64_decode(_time)
#         _value = time.time() - float(_time)
#         if _value >= config.TOKEN_OUT_TIME:
#             abort(401)
